﻿using SocialFront.Providers.Document;
using SocialFront.Providers.Member;

namespace SocialFront.BusinessLogic
{
    public static class BusinessLogic
    {

        public static string CreateMemberSpace(Entities.Member member)
        {
            //// Log the user into the system
            member = MemberProvider.Provider.LoginMember(member);

            //// Create a members area node in the content tree for the member
            //Document membersArea = Document.MakeNew(_umbUsername.Text, DocumentType.GetByAlias("member"),
            //                 systemUser, Config.sfMembersNodeId);
            string memberUrl = DocumentProvider.Provider.MakeMembersArea(member);

            //// Relate the new node to the member
            //Relation.MakeNew(m.Id, membersArea.Id, RelationType.GetByAlias("relateMemberToMemberDocType"),
            //                 String.Format("Relating content folder {0} to member {1}", membersArea.Text,
            //                               m.LoginName));

            //// Create a blog node in this new member's area for the member
            //Document membersBlog = Document.MakeNew("Blog", DocumentType.GetByAlias("blog"),
            //                                        systemUser, membersArea.Id);

            //// Relate the new node to the member
            //Relation.MakeNew(m.Id, membersBlog.Id, RelationType.GetByAlias("relateMemberToBlogDocType"),
            //                 String.Format("Relating blog folder {0} to member {1}", membersBlog.Id,
            //                               m.LoginName));

            //// Create a gallery node in this new member's area for the member
            //Document membersGallery = Document.MakeNew("Gallery", DocumentType.GetByAlias("gallery"),
            //                                        systemUser, membersArea.Id);

            //// Relate the new node to the member
            //Relation.MakeNew(m.Id, membersGallery.Id, RelationType.GetByAlias("relateMemberToGalleryDocType"),
            //                 String.Format("Relating gallery folder {0} to member {1}", membersGallery.Id,
            //                               m.LoginName));

            //// Publish the new folders, setting blog and gallery to enabled = false
            //membersArea.getProperty("pageTitle").Value = String.Format("{0}'s area", m.LoginName);
            //membersArea.Save();
            //membersArea.Publish(systemUser);
            //umbraco.library.UpdateDocumentCache(membersArea.Id);

            //membersBlog.getProperty("pageTitle").Value = String.Format("{0}'s blog", m.LoginName);
            //membersBlog.getProperty("title").Value = String.Format("{0}'s blog", m.LoginName);
            //membersBlog.getProperty("enabled").Value = false;
            //membersBlog.Save();
            //membersBlog.Publish(systemUser);
            //umbraco.library.UpdateDocumentCache(membersBlog.Id);

            //membersGallery.getProperty("pageTitle").Value = String.Format("{0}'s gallery", m.LoginName);
            //membersGallery.getProperty("title").Value = String.Format("{0}'s gallery", m.LoginName);
            //membersGallery.getProperty("enabled").Value = false;
            //membersGallery.Save();
            //membersGallery.Publish(systemUser);
            //umbraco.library.UpdateDocumentCache(membersGallery.Id);

            return memberUrl;
        }
    }
}
